package logic

import (
	"context"
	"errors"
	"newwechat/models/mysql"

	"newwechat/wechatrpc/internal/svc"
	"newwechat/wechatrpc/wechatrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserDetailLogic {
	return &UserDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 用户信息详情
func (l *UserDetailLogic) UserDetail(in *wechatrpc.UserDetailRequest) (*wechatrpc.UserDetailResponse, error) {
	// todo: add your logic here and delete this line
	var user mysql.User
	err := user.FindUserByUserId(mysql.DB, in.UserId)
	if err != nil {
		return nil, errors.New("用户未注册")
	}
	return &wechatrpc.UserDetailResponse{
		Mobile:    user.Mobile,
		Password:  user.Password,
		HeadImage: user.HeadImage,
		NickName:  user.NickName,
		Address:   user.Address,
	}, nil
}
